<?php
require 'config/dataSource.php';
if (isset($_GET['email'])) {
    $email = mysql_real_escape_string($_GET['email']);
    $email = strip_tags($email);
    $queryEmail = mysql_query("SELECT email, firstName,lastName FROM user");
    $emailFound = false;
    $firstName = "";
    $lastName = "";
    $emailCheck = "";
    $display = "";
    while ($row = mysql_fetch_assoc($queryEmail)) {
        $emailCheck = $row['email'];
        $firstName = $row['firstName'];
        $lastName = $row['lastName'];
        if ($email == sha1($emailCheck)) {
            $userUpdateQuery = mysql_query("UPDATE user SET emailVerify='t' WHERE email='" . $emailCheck . "'");
            $display.="<br/><br/>Congratulation, " . $firstName . " " . $lastName . "!<br/>";
            $display.="<br/><br/>";
            $display.="Your email " . $emailCheck . " has been verified.";
            $display.="<br/><br/><br/><br/><br/>";
            $display.="Regards,<br/>";
            $display.="Team 5 Waggle Project<br/>";
            $emailFound = true;
            break;
        }
    }
    if (!($emailFound)) {
        $display.="<br/><br/>Ooops...<br/><br/>";
        $display.="This is awkward. We could not find your email in our database.<br/>";
        $display.="<a class=\"error\" href=\"newAccount.php\">Please register again.</a><br/>";
        $display.="<br/><br/><br/>";
        $display.="Regards,<br/>";
        $display.="Team 5 Waggle Project<br/>";
    }
}
?>
<html>
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="css/newAccount.css">
        <title>Email Verification</title>
    </head>
    <body style="background: url(images/background.jpg);">
        <div id="wrapper">

            <div id="head">

                <span>Return to log in page? <a class="newAccount" href="index.php">Go Home!</a></span>

            </div>
            <div id="container2">
                <label align ="center" class="label2">
                    <?php
                    if (isset($display)) {

                        echo $display;
                    }
                    ?>
                </label>
            </div>
    </body>
</html>

